package com.blensmile.activity;

import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;

import com.blensmile.BaseActivity;
import com.blensmile.R;
import com.blensmile.utils.LogUtils;

public class MediaPlayerItemTestActivity extends BaseActivity {

    private MediaPlayer player;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_media_player_item_test);
        url = getIntent().getStringExtra("url");
        LogUtils.b(getIntent().getParcelableArrayListExtra("data").toString());
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(!TextUtils.isEmpty(url)){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        player = MediaPlayer.create(MediaPlayerItemTestActivity.this, Uri.parse(url));
                        player.setLooping(true);
                        player.start();
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(player != null){
            player.release();
            player = null;
        }
    }

    @Override
    public void onBackPressed() {
        System.exit(1);
    }
}
